package mygang.controller;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import mygang.helper.JsonHelper;
import mygang.model.constructor.Form;
import mygang.service.ConstructorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 */
@Controller
public class HelloController extends AbstractController {

//    @Resource(name="sessionRegistry")
//    private SessionRegistryImpl sessionRegistry;
    
    @Autowired
    private ConstructorService constructorService;
    
    
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public void register(HttpServletResponse response) throws IOException {
        Form form = constructorService.getForm(1, 0);
        //log.debug(form);
        JsonHelper.prepareJsonResponse(form, response);
    }
    
    @RequestMapping("/hello")
    public ModelAndView hello() {
        return new ModelAndView("hello");
    }
    
    @RequestMapping("/")
    public ModelAndView home() {
        return new ModelAndView("index");
    }
    
//    @RequestMapping(value = "/users", method = RequestMethod.GET)
//    public String getUsersPage(Model model) {
//        log.debug("Received request to show users page");
//
//        log.debug("Total logged-in users: " + sessionRegistry.getAllPrincipals().size());
//        log.debug("List of logged-in users: ");
//        for (Object username : sessionRegistry.getAllPrincipals()) {
//            log.debug(username);
//        }
//        log.debug("Total sessions including expired ones: " + sessionRegistry.getAllSessions(sessionRegistry.getAllPrincipals().get(0), true).size());
//        log.debug("Total sessions: " + sessionRegistry.getAllSessions(sessionRegistry.getAllPrincipals().get(0), false).size());
//
//        // Attach to model list of users and granted authorities
//        model.addAttribute("users", sessionRegistry.getAllPrincipals());
//        model.addAttribute("total", sessionRegistry.getAllPrincipals().size());
//
//        // This will resolve to /WEB-INF/jsp/userspage.jsp
//        return "userspage";
//    }
}
